<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/prettyphoto.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.mselect.old.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/json.js"></script>
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.prettyphoto.js"></script>
<script type="text/javascript">
get_check = function(){
	var ids = new Array();
	$("#list").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			ids.push($(this).val());
		}
	});
	return ids;
}
$(function(){
	$("a[rel^='pretty_photo']").prettyPhoto({theme:'facebook'});
	var website_categories_data = <?=isset($website_categories) ? $website_categories : '[]'?>;
	var selected = [<?=isset($_GET['website_id']) ? $_GET['website_id'] : ''?>, <?=isset($_GET['website_cat_1']) ? $_GET['website_cat_1'] : ''?>, <?=isset($_GET['website_cat_2']) ? $_GET['website_cat_2'] : ''?>, <?=isset($_GET['website_cat_3']) ? $_GET['website_cat_3'] : ''?>];
	$(document).mselect(website_categories_data, ['website_id','website_cat_1','website_cat_2','website_cat_3'], ['','','',''], selected);
	$(document).mselect(website_categories_data, ['move_select_website_id','move_select_website_cat_1','move_select_website_cat_2','move_select_website_cat_3'], ['','','',''],['','','','']);
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$("#list input[type='checkbox']").attr("checked", true);
		}
		else
		{
			$("#list input[type='checkbox']").attr("checked", false);
		}
	});
	$("#export_check_btn").click(function(){
		var ids = get_check();
		if (ids.length == 0)
		{
			alert("请选择产品");
			return false;
		}
		$("#ids").val($.toJSON(ids));
		$("#action_form").attr("action", "<?=url('Online::Zencart/ExportCheck')?>");
		$("#action_form").submit();
	});
	$("#export_search_btn").click(function(){
		$("#action_form").attr("action", "<?=url('Online::Zencart/ExportSearch')?>");
		$("#action_form").submit();
	});
	$("#move_check_btn").click(function(){
		var ids = get_check();
		if (ids.length == 0)
		{
			alert("请选择产品");
			return false;
		}
		$("#ids").val($.toJSON(ids));
		$("#move_website_id").val($("#move_select_website_id").val());
		$("#move_website_cat_1").val($("#move_select_website_cat_1").val());
		$("#move_website_cat_2").val($("#move_select_website_cat_2").val());
		$("#move_website_cat_3").val($("#move_select_website_cat_3").val());
		$("#action_form").attr("action", "<?=url('Online::Zencart/MoveCategoriesCheck')?>");
		$("#action_form").submit();
	});
	$("#move_search_btn").click(function(){
		$("#move_website_id").val($("#move_select_website_id").val());
		$("#move_website_cat_1").val($("#move_select_website_cat_1").val());
		$("#move_website_cat_2").val($("#move_select_website_cat_2").val());
		$("#move_website_cat_3").val($("#move_select_website_cat_3").val());
		$("#action_form").attr("action", "<?=url('Online::Zencart/MoveCategoriesSearch')?>");
		$("#action_form").submit();
	});
	$("#onsale_check_btn").click(function(){
		var ids = get_check();
		if (ids.length == 0)
		{
			alert("请选择产品");
			return false;
		}
		$("#ids").val($.toJSON(ids));
		$("#onsale_val").val($("#onsale_select").val());
		$("#action_form").attr("action", "<?=url('Online::Zencart/OnSaleCheck')?>");
		$("#action_form").submit();
	});
	$("#onsale_search_btn").click(function(){
		$("#onsale_val").val($("#onsale_select").val());
		$("#action_form").attr("action", "<?=url('Online::Zencart/OnSaleSearch')?>");
		$("#action_form").submit();
	});
	$("#multiedit_check_btn").click(function(){
		var ids = get_check();
		if (ids.length == 0)
		{
			alert("请选择产品");
			return false;
		}
		$("#ids").val($.toJSON(ids));
		$("#price").val($("#price_input").val());
		$("#storage").val($("#storage_input").val());
		$("#action_form").attr("action", "<?=url('Online::Zencart/MultiEditCheck')?>").submit();
	});
	$("#multiedit_search_btn").click(function(){
		$("#price").val($("#price_input").val());
		$("#storage").val($("#storage_input").val());
		$("#action_form").attr("action", "<?=url('Online::Zencart/MultiEditSearch')?>").submit();
	});
	$("#push_check_btn").click(function(){
		if (confirm("推送到网站？？"))
		{
			var ids = get_check();
			if (ids.length == 0)
			{
				alert("请选择产品");
				return false;
			}
			$("#ids").val($.toJSON(ids));
			$("#action_form").attr("action", "<?=url('Online::Zencart/PushCheck')?>");
			$("#action_form").submit();
		}
	});
	$("#push_search_btn").click(function(){
		if (confirm("推送到网站？？"))
		{
			$("#action_form").attr("action", "<?=url('Online::Zencart/PushSearch')?>");
			$("#action_form").submit();
		}
	});
});
</script>
<fieldset><legend>查询条件</legend>
<form method="get" action="">
<?include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tr>
	<th>产品编号</th>
	<td>
		<input type="text" name="start_number" value="<?=isset($_GET['start_number'])?$_GET['start_number']:''?>" /> to 
		<input type="text" name="end_number" value="<?=isset($_GET['end_number'])?$_GET['end_number']:''?>" /> 填写后六位，例如：000001
	</td>
</tr>
<tr>
	<th>网站分类</th>
	<td>
		<select id="website_id" name="website_id"></select>
		<select id="website_cat_1" name="website_cat_1"></select>
		<select id="website_cat_2" name="website_cat_2"></select>
		<select id="website_cat_3" name="website_cat_3"></select>
	</td>
</tr>
<tr>
	<th>产品名称</th>
	<td><input type="text" name="product_name" value="<?=isset($_GET['product_name'])?$_GET['product_name']:''?>" /></td>
</tr>
<tr>
	<th>上传的文件</th>
	<td>
		<select name="file_id">
			<option value=""></option>
			<? foreach ($file as $f):?>
			<option value="<?=$f['id']?>" <? if (isset($_GET['file_id']) and $_GET['file_id'] == $f['id']):?>selected="selected"<? endif;?>><?=$f['name']?></option>
			<? endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>上下架状态</th>
	<td>
		<?foreach (Q::ini('custom_flag/online_zencart_onsale_flag') as $of):?>
		<label><input type="checkbox" name="onsale_flag[<?=$of['value']?>]" value="<?=$of['value']?>" <?if (isset($_GET['onsale_flag']) &&  array_key_exists($of['value'], $_GET['onsale_flag'])) echo "checked='checked'"?> /> <?=$of['name']?></label>
		<?endforeach;?>
	</td>
</tr>
<tr>
	<th>高级查询</th>
	<td><input type="text" name="product_number" value="<?=isset($_GET['product_number']) ? $_GET['product_number'] : ''?>" /></td>
</tr>
<tr>
	<th></th>
	<td><input type="submit" class="button" value="查询" /></td>
</tr>
</table>
</form>
</fieldset>
<table width="100%" class="list_table" id="list">
<tr>
	<th width="70">产品编号</th>
	<th width="115">网站</th>
	<th>标题名称</th>
	<th width="50">图片</th>
	<th width="50">状态</th>
	<th width="80">重量（g）</th>
	<th width="60">实际库存</th>
	<th width="50">操作</th>
</tr>
<?foreach ($product as $p):?>
<tr>
	<td><label><input type="checkbox" value="<?=$p['id']?>" /> <?=$p['number']?></label></td>
	<td><?=$p['shop_name']?></td>
	<td align="left"><?=$p['title']?></td>
	<td align="center" valign="middle">
		<?if ($p['pic_url']):?>
			<?$pretty_photo_number = 0;?>
			<?foreach ($p['pic_url'] as $ppu):?>
			<a rel="pretty_photo[<?=$p['id']?>]" href="<?=$ppu?>"><?if(!$pretty_photo_number):?><img width="50" src="<?=$ppu?>" /><?endif;?></a>
			<?$pretty_photo_number = 1;?>
			<?endforeach;?>
		<?endif;?>
	</td>
	<td>
		<? foreach (Q::ini('custom_flag/online_zencart_onsale_flag') as $flag):
			if ($flag['value'] == $p['onsale_flag']) echo $flag['name'];
		endforeach;?>
	</td>
	<td><?=sprintf('%.3f', $p['weight'])?></td>
	<td><?=$p['actual_quantity']?></td>
	<td><a href="<?=url('Online::Zencart/Edit', array('id' => $p['id']))?>">编辑</a></td>
</tr>
<?endforeach;?>
</table>
<?=$page?>
<table  width="100%" class="list_table">
<tr>
	<td rowspan="5" width="60"><label><input type="checkbox" id="check_all" /> 全选</label></td>
	<td width="65">导出</td>
	<td></td>
	<td width="200">
		<input type="button" class="button" value="按勾选" id="export_check_btn" />
		<input type="button" class="button" value="按条件" id="export_search_btn" />
	</td>
</tr>
<tr>
	<td>分类移动</td>
	<td>
		<select id="move_select_website_id"></select>
		<select id="move_select_website_cat_1"></select>
		<select id="move_select_website_cat_2"></select>
		<select id="move_select_website_cat_3"></select>
	</td>
	<td>
		<input type="button" class="button" value="按勾选" id="move_check_btn" />
		<input type="button" class="button" value="按条件" id="move_search_btn" />
	</td>
</tr>
<tr>
	<td>上下架</td>
	<td>
		<select id="onsale_select">
		<? foreach (Q::ini('custom_flag/online_zencart_onsale_flag') as $flag): ?>
			<option value="<?=$flag['value']?>"><?=$flag['name']?></option>
		<? endforeach;?>
		</select>
	</td>
	<td>
		<input type="button" class="button" value="按勾选" id="onsale_check_btn" />
		<input type="button" class="button" value="按条件" id="onsale_search_btn" />
	</td>
</tr>
<tr>
	<td>价格/库存</td>
	<td>
		价格 <input type="text" size="6" id="price_input"  />
		网站库存 <input type="text" size="6" id="storage_input" />
	</td>
	<td>
		<input type="button" class="button" value="按勾选" id="multiedit_check_btn" />
		<input type="button" class="button" value="按条件" id="multiedit_search_btn" />
	</td>
</tr>
<tr>
	<td>推送</td>
	<td></td>
	<td>
		<input type="button" class="button" value="按勾选" id="push_check_btn" />
		<input type="button" class="button" value="按条件" id="push_search_btn" />
	</td>
</tr>
</table>
<form id="action_form" action="" method="post">
	<input type="hidden" name="url_arr" value='<?=$url_arr?>' />
	<input type="hidden" name="ids" id="ids" value="" />
	<input type="hidden" name="move_website_id" id="move_website_id" value="" />
	<input type="hidden" name="move_website_cat_1" id="move_website_cat_1" value="" />
	<input type="hidden" name="move_website_cat_2" id="move_website_cat_2" value="" />
	<input type="hidden" name="move_website_cat_3" id="move_website_cat_3" value="" />
	<input type="hidden" name="onsale_val" id="onsale_val" value="" />
	<input type="hidden" name="price" id="price" value="" />
	<input type="hidden" name="storage" id="storage" value="" />
</form>
<?php $this->_endblock(); ?>